/****************************************
*  This file created using "Writer B"   *
*      a program written by CTonk       *
*          ctonk87@hotmail.com          *
*     [timestamp 03/04/06  15:17:35]    *
****************************************/

// Creature.cpp

#ifndef CPP_CREATURE
#define CPP_CREATURE

#include "Creature.h"



// Constructors...
Creature::Creature()
{
	_socket = new Socket;
	_gotinput = false;
	_connected = true;

	_name = new char[30];
	for ( int x=0; x < 30; x++ )
		_name[x] = '\0';
	strcpy( _name, "_name" );
	_prompt = new char[80];
	for ( int x=0; x < 80; x++ )
		_prompt[x] = '\0';
	strcpy( _prompt, "{W[ {Rp{Br{Go{Ym{Mp{Ct {W]" );
	_race = 0;
	_class = 0;
	_goldheld = 0;
	_silverheld = 0;
	_pos = 0;
	_room = 0;
	_level = 0;
	_mstr = 0;
	_str = 0;
	_mdex = 0;
	_dex = 0;
	_mcon = 0;
	_con = 0;
	_mintel = 0;
	_intel = 0;
	_mwis = 0;
	_wis = 0;
	_mhp = 0;
	_hp = 0;
	_mmana = 0;
	_mana = 0;
	_mmove = 0;
	_move = 0;
	_ac = 0;
	_acbash = 0;
	_acslash = 0;
	_acpierce = 0;
	_acexotic = 0;
	_hr = 0;
	_dr = 0;
	_saves = 0;
	_wimpy = 0;
	_gender = 0;
	_height = 0;
	_weight = 0;
	_witems = 0;
	_age = 0;
}

Creature::Creature( Creature& it )
{
	_socket = it._socket;
	_gotinput = it._gotinput;
	_connected = it._connected;

	for ( int x=0; x < 30; x++ )
		_name[x] = it._name[x];
	for ( int x=0; x < 30; x++ )
		_prompt[x] = it._prompt[x];
	_race = it._race;
	_class = it._class;
	_goldheld = it._goldheld;
	_silverheld = it._silverheld;
	_pos = it._pos;
	*_room = *(it._room);
	_level = it._level;
	_mstr = it._mstr;
	_str = it._str;
	_mdex = it._mdex;
	_dex = it._dex;
	_mcon = it._mcon;
	_con = it._con;
	_mintel = it._mintel;
	_intel = it._intel;
	_mwis = it._mwis;
	_wis = it._wis;
	_mhp = it._mhp;
	_hp = it._hp;
	_mmana = it._mmana;
	_mana = it._mana;
	_mmove = it._mmove;
	_move = it._move;
	_ac = it._ac;
	_acbash = it._acbash;
	_acslash = it._acslash;
	_acpierce = it._acpierce;
	_acexotic = it._acexotic;
	_hr = it._hr;
	_dr = it._dr;
	_saves = it._saves;
	_wimpy = it._wimpy;
	_gender = it._gender;
	_height = it._height;
	_weight = it._weight;
	_witems = it._witems;
	_age = it._age;
}

Creature::~Creature()
{
	if ( _socket )
	{
		if ( !_socket->GetSocketIP().empty() )
		{
			SocketServer::Instance()._socketList.remove( _socket );
			SocketServer::Instance().KillSocket( _socket ); 
		}
		delete _socket; _socket = 0;
	}

	delete[] _name;
	delete _room;
}

// Operators...
Creature& Creature::operator = ( Creature& it )
{
	_socket = it._socket;
	_gotinput = it._gotinput;
	_connected = it._connected;

	for ( int x=0; x < 30; x++ )
		_name[x] = it._name[x];
	for ( int x=0; x < 30; x++ )
		_prompt[x] = it._prompt[x];
	_race = it._race;
	_class = it._class;
	_goldheld = it._goldheld;
	_silverheld = it._silverheld;
	_pos = it._pos;
	*_room = *(it._room);
	_level = it._level;
	_mstr = it._mstr;
	_str = it._str;
	_mdex = it._mdex;
	_dex = it._dex;
	_mcon = it._mcon;
	_con = it._con;
	_mintel = it._mintel;
	_intel = it._intel;
	_mwis = it._mwis;
	_wis = it._wis;
	_mhp = it._mhp;
	_hp = it._hp;
	_mmana = it._mmana;
	_mana = it._mana;
	_mmove = it._mmove;
	_move = it._move;
	_ac = it._ac;
	_acbash = it._acbash;
	_acslash = it._acslash;
	_acpierce = it._acpierce;
	_acexotic = it._acexotic;
	_hr = it._hr;
	_dr = it._dr;
	_saves = it._saves;
	_wimpy = it._wimpy;
	_gender = it._gender;
	_height = it._height;
	_weight = it._weight;
	_witems = it._witems;
	_age = it._age;
	return *this;
}

// Public accessor methods...
Socket* Creature::GetSocket()
{
	return _socket;
}

void Creature::SetSocket( Socket* socket )
{
	_socket = socket;
	return;
}

bool Creature::GetGotinput()
{
	return _gotinput;
}

void Creature::SetGotinput( bool gotinput )
{
	_gotinput = gotinput;
	return;
}

bool Creature::GetConnected()
{
	return _connected;
}

void Creature::SetConnected( bool connected )
{
	_connected = connected;
	return;
}

Magiclist< Object* >& Creature::GetInventory()
{
	return _inventory;
}

Object*	Creature::GetObject( int offset )
{
	return _inventory[offset];
}

Object*	Creature::Add( Object* obj )
{
	return _inventory.Add( obj );
}

void Creature::Remove( Object* obj )
{
	_inventory.Remove( obj );
}

char* Creature::GetName( void )
{
	return _name;
}

char Creature::GetName( int x )
{
	return _name[x];
}

void Creature::SetName( char* val )
{
	strcpy( _name, val );
	return;
}

void Creature::SetName( const char* val )
{
	strcpy( _name, val );
	return;
}

void Creature::SetName( int x, char val )
{
	_name[x] = val;
}

char* Creature::GetPrompt( void )
{
	return _prompt;
}

int Creature::GetRace()
{
	return _race;
}

void Creature::SetRace( int race )
{
	_race = race;
}

int Creature::GetClass()
{
	return _class;
}

void Creature::SetClass( int Class )
{
	_class = Class;
}

int Creature::GetGoldheld()
{
	return _goldheld;
}

void Creature::SetGoldheld( int goldheld )
{
	_goldheld = goldheld;
}

int Creature::GetSilverheld()
{
	return _silverheld;
}

void Creature::SetSilverheld( int silverheld )
{
	_silverheld = silverheld;
}

int Creature::GetPos()
{
	return _pos;
}

void Creature::SetPos( int pos )
{
	_pos = pos;
}

Room* Creature::GetRoom()
{
	return _room;
}

void Creature::SetRoom( int number )
{
	_room = World::Instance().FindRoom( number );
}

int Creature::GetLevel()
{
	return _level;
}

void Creature::SetLevel( int level )
{
	_level = level;
}

int Creature::GetMstr()
{
	return _mstr;
}

void Creature::SetMstr( int mstr )
{
	_mstr = mstr;
}

int Creature::GetStr()
{
	return _str;
}

void Creature::SetStr( int str )
{
	_str = str;
}

int Creature::GetMdex()
{
	return _mdex;
}

void Creature::SetMdex( int mdex )
{
	_mdex = mdex;
}

int Creature::GetDex()
{
	return _dex;
}

void Creature::SetDex( int dex )
{
	_dex = dex;
}

int Creature::GetMcon()
{
	return _mcon;
}

void Creature::SetMcon( int mcon )
{
	_mcon = mcon;
}

int Creature::GetCon()
{
	return _con;
}

void Creature::SetCon( int con )
{
	_con = con;
}

int Creature::GetMintel()
{
	return _mintel;
}

void Creature::SetMintel( int mintel )
{
	_mintel = mintel;
}

int Creature::GetIntel()
{
	return _intel;
}

void Creature::SetIntel( int intel )
{
	_intel = intel;
}

int Creature::GetMwis()
{
	return _mwis;
}

void Creature::SetMwis( int mwis )
{
	_mwis = mwis;
}

int Creature::GetWis()
{
	return _wis;
}

void Creature::SetWis( int wis )
{
	_wis = wis;
}

int Creature::GetMhp()
{
	return _mhp;
}

void Creature::SetMhp( int mhp )
{
	_mhp = mhp;
}

int Creature::GetHp()
{
	return _hp;
}

void Creature::SetHp( int hp )
{
	_hp = hp;
}

int Creature::GetMmana()
{
	return _mmana;
}

void Creature::SetMmana( int mmana )
{
	_mmana = mmana;
}

int Creature::GetMana()
{
	return _mana;
}

void Creature::SetMana( int mana )
{
	_mana = mana;
}

int Creature::GetMmove()
{
	return _mmove;
}

void Creature::SetMmove( int mmove )
{
	_mmove = mmove;
}

int Creature::GetMove()
{
	return _move;
}

void Creature::SetMove( int move )
{
	_move = move;
}

int Creature::GetAc()
{
	return _ac;
}

void Creature::SetAc( int ac )
{
	_ac = ac;
}

int Creature::GetAcbash()
{
	return _acbash;
}

void Creature::SetAcbash( int acbash )
{
	_acbash = acbash;
}

int Creature::GetAcslash()
{
	return _acslash;
}

void Creature::SetAcslash( int acslash )
{
	_acslash = acslash;
}

int Creature::GetAcpierce()
{
	return _acpierce;
}

void Creature::SetAcpierce( int acpierce )
{
	_acpierce = acpierce;
}

int Creature::GetAcexotic()
{
	return _acexotic;
}

void Creature::SetAcexotic( int acexotic )
{
	_acexotic = acexotic;
}

int Creature::GetHr()
{
	return _hr;
}

void Creature::SetHr( int hr )
{
	_hr = hr;
}

int Creature::GetDr()
{
	return _dr;
}

void Creature::SetDr( int dr )
{
	_dr = dr;
}

int Creature::GetSaves()
{
	return _saves;
}

void Creature::SetSaves( int saves )
{
	_saves = saves;
}

int Creature::GetWimpy()
{
	return _wimpy;
}

void Creature::SetWimpy( int wimpy )
{
	_wimpy = wimpy;
}

int Creature::GetGender()
{
	return _gender;
}

void Creature::SetGender( int gender )
{
	_gender = gender;
}

int Creature::GetHeight()
{
	return _height;
}

void Creature::SetHeight( int height )
{
	_height = height;
}

int Creature::GetWeight()
{
	return _weight;
}

void Creature::SetWeight( int weight )
{
	_weight = weight;
}

int Creature::GetWitems()
{
	return _witems;
}

void Creature::SetWitems( int witems )
{
	_witems = witems;
}

int Creature::GetAge()
{
	return _age;
}

void Creature::SetAge( int age )
{
	_age = age;
}

// Other methods...
void Creature::FlushOutput()
{
	std::string output;
	// This will add a prompt to the end of output
	// Of course, one needs some text before it'll add a prompt
	// or we can add a prompt if we get some input and it calls for it. :)

	output = _socket->GetOutput();
	if ( !output.empty() || _gotinput )
	{
		if ( _gotinput )
		{
			if ( _socket->GetInput().empty() )
				_gotinput = false;
			else
				_gotinput = true;
		}

		output << '\n' << _prompt << '\n';
		_socket->SetOutput( output );
	}

	return;
}

void Creature::Send( const std::string& message )
{
	std::string output = _socket->GetOutput();
	output << message;
	_socket->SetOutput( output );
	return;
}

void Creature::Send( char * message, ... )
{
	va_list args;
	char buf[MAX_BUFFER];
	std::string buf2;

    va_start( args, message );

	vsprintf( buf, message, args);
	buf2 = _socket->GetOutput();
	buf2.append( buf );
	
	_socket->SetOutput( buf2 );
	va_end( args );
}

void Creature::Set( char* message, int space, int align = LEFT ) {

	return;
}

void Creature::Set( std::string& message, int space, int align = LEFT ) {

	return;
}

void Creature::Display( std::ostream& out )
{
	out << "-Creature-";
	out << "\nName: " << _name;
	out << "\nRace: " << _race;
	out << "\nClass: " << _class;
	out << "\nGoldheld: " << _goldheld;
	out << "\nSilverheld: " << _silverheld;
	out << "\nPos: " << _pos;
	out << "\nLevel: " << _level;
	out << "\nMstr: " << _mstr;
	out << "\nStr: " << _str;
	out << "\nMdex: " << _mdex;
	out << "\nDex: " << _dex;
	out << "\nMcon: " << _mcon;
	out << "\nCon: " << _con;
	out << "\nMintel: " << _mintel;
	out << "\nIntel: " << _intel;
	out << "\nMwis: " << _mwis;
	out << "\nWis: " << _wis;
	out << "\nMhp: " << _mhp;
	out << "\nHp: " << _hp;
	out << "\nMmana: " << _mmana;
	out << "\nMana: " << _mana;
	out << "\nMmove: " << _mmove;
	out << "\nMove: " << _move;
	out << "\nAc: " << _ac;
	out << "\nAcbash: " << _acbash;
	out << "\nAcslash: " << _acslash;
	out << "\nAcpierce: " << _acpierce;
	out << "\nAcexotic: " << _acexotic;
	out << "\nHr: " << _hr;
	out << "\nDr: " << _dr;
	out << "\nSaves: " << _saves;
	out << "\nWimpy: " << _wimpy;
	out << "\nGender: " << _gender;
	out << "\nHeight: " << _height;
	out << "\nWeight: " << _weight;
	out << "\nWitems: " << _witems;
	out << "\nAge: " << _age;
	return;
}

void Creature::Display( std::string& out )
{
	out << "-Creature-";
	out << "\nName: " << _name;
	out << "\nRace: " << _race;
	out << "\nClass: " << _class;
	out << "\nGoldheld: " << _goldheld;
	out << "\nSilverheld: " << _silverheld;
	out << "\nPos: " << _pos;
	out << "\nLevel: " << _level;
	out << "\nMstr: " << _mstr;
	out << "\nStr: " << _str;
	out << "\nMdex: " << _mdex;
	out << "\nDex: " << _dex;
	out << "\nMcon: " << _mcon;
	out << "\nCon: " << _con;
	out << "\nMintel: " << _mintel;
	out << "\nIntel: " << _intel;
	out << "\nMwis: " << _mwis;
	out << "\nWis: " << _wis;
	out << "\nMhp: " << _mhp;
	out << "\nHp: " << _hp;
	out << "\nMmana: " << _mmana;
	out << "\nMana: " << _mana;
	out << "\nMmove: " << _mmove;
	out << "\nMove: " << _move;
	out << "\nAc: " << _ac;
	out << "\nAcbash: " << _acbash;
	out << "\nAcslash: " << _acslash;
	out << "\nAcpierce: " << _acpierce;
	out << "\nAcexotic: " << _acexotic;
	out << "\nHr: " << _hr;
	out << "\nDr: " << _dr;
	out << "\nSaves: " << _saves;
	out << "\nWimpy: " << _wimpy;
	out << "\nGender: " << _gender;
	out << "\nHeight: " << _height;
	out << "\nWeight: " << _weight;
	out << "\nWitems: " << _witems;
	out << "\nAge: " << _age;
	return;
}

void Creature::Csave( std::ofstream& save ) {

	Time::clock clock;
	save << clock.GetDate() << " @ " << clock.GetTime();

	save << "\n\n// Creature Data...";
	save << "\nName: " << _name;
	save << "\nRace: " << _race;
	save << "\nClass: " << _class;
	save << "\nGoldheld: " << _goldheld;
	save << "\nSilverheld: " << _silverheld;
	save << "\nPos: " << _pos;
	save << "\nRoom: " << _room->GetVnum();
	save << "\nLevel: " << _level;
	save << "\nStr: " << _str << ' ' << _mstr;
	save << "\nDex: " << _dex << ' ' << _mdex;
	save << "\nCon: " << _con << ' ' << _mcon;
	save << "\nIntel: " << _intel << ' ' << _mintel;
	save << "\nWis: " << _wis << ' ' << _mwis;
	save << "\nHMV: " << _hp << ' ' << _mhp << ' ' << _mana << ' ' << _mmana << ' '<< _move << ' ' << _mmove;
	save << "\nAc: " << _ac << ' '<< _acbash << ' '<< _acslash << ' '<< _acpierce << ' '<< _acexotic;
	save << "\nhr/dr/sv: " << _hr << ' '<< _dr << ' '<< _saves;
	save << "\nWimpy: " << _wimpy;
	save << "\nGender: " << _gender;
	save << "\nHeight: " << _height;
	save << "\nWeight: " << _weight;
	save << "\nWitems: " << _witems;
	save << "\nAge: " << _age;

	return;
}

void Creature::Cload( std::ifstream& load ) {
	char* temp = new char[1024];
	int i = 0;
	init( temp );

	for ( int x=0; x < 4; x++ )
		load.getline( temp, 1024 );
	parse( temp );
	strcpy( _name, arg[1] );
	load >> temp >> _race; load.get();
	load >> temp >> _class; load.get();
	load >> temp >> _goldheld; load.get();
	load >> temp >> _silverheld; load.get();
	load >> temp >> _pos; load.get();
	load >> temp >> i; load.get();
	this->SetRoom( i );
	load >> temp >> _level; load.get();
	load >> temp >> _str >> _mstr; load.get();
	load >> temp >> _dex >> _mdex; load.get();
	load >> temp >> _con >> _mcon; load.get();
	load >> temp >> _intel >> _mintel; load.get();
	load >> temp >> _wis >> _mwis; load.get();
	load >> temp >> _hp >> _mhp >> _mana >> _mmana >> _move >> _mmove; load.get();
	load >> temp >> _ac >> _acbash >> _acslash >> _acpierce >> _acexotic; load.get();
	load >> temp >> _hr >> _dr >> _saves; load.get();
	load >> temp >> _wimpy; load.get();
	load >> temp >> _gender; load.get();
	load >> temp >> _height; load.get();
	load >> temp >> _weight; load.get();
	load >> temp >> _witems; load.get();
	load >> temp >> _age; load.get();

	return;
}




#endif // #ifndef CPP_CREATURE